package com.gitee.wsl.mathematics.vector.ext

import com.gitee.wsl.mathematics.base.NumberMapping2
import com.gitee.wsl.mathematics.base.NumberMapping3
import com.gitee.wsl.mathematics.base.NumberMapping4
import com.gitee.wsl.mathematics.vector.vec2.Vector2
import com.gitee.wsl.mathematics.vector.vec3.Vector3
import com.gitee.wsl.mathematics.vector.vec4.Vector4


/** Summed values of respective components of [this] and [k]*[b] reduced by [out]. */
private inline fun <T:Number,K: Vector2<T, K>,R> Vector2<T, K>.plusScaled(k: T, v: Vector2<T, *>, out: NumberMapping2<T,R>) =
    mapReduce(v, {a,b-> a + k * b }){a,b -> out(a,b)}

/** Summed values of respective components of [this] and [k]*[b] reduced by [out]. */
private inline fun <T:Number,K: Vector3<T, K>,R> Vector3<T, K>.plusScaled(k: T, v: Vector3<T, *>, out: NumberMapping3<T,R>) =
    mapReduce(v, {a,b-> a + k * b }){a,b,c -> out(a,b,c)}

/** Summed values of respective components of [this] and [k]*[b] reduced by [out]. */
private inline fun  <T:Number,K: Vector4<T, K>,R> Vector4<T, K>.plusScaled(k: T, v: Vector4<T, *>, out: NumberMapping4<T,R>) =
    mapReduce(v, {a,b-> a + k * b }){a,b,c,d  -> out(a,b,c,d)}

/** Create a new [MutableVec2] vector initialized with summed values of respective components of [this] and [k]*[b]. */
fun <T:Number,K: Vector2<T, K>> Vector2<T, K>.plusScaled(k: T, v: Vector2<T, *>) = plusScaled(k, v){a,b->create(a,b)}

/** Create a new [MutableVec3] vector initialized with summed values of respective components of [this] and [k]*[b]. */
fun <T:Number,K: Vector3<T, K>> Vector3<T, K>.plusScaled(k: T, v: Vector3<T, *>)  = plusScaled(k, v){a,b,c ->create(a,b,c)}

/** Create a new [MutableVec4] vector initialized with summed values of respective components of [this] and [k]*[b]. */
fun <T:Number,K: Vector4<T, K>> Vector4<T, K>.plusScaled(k: T, v: Vector4<T, *>) = plusScaled(k, v){a,b,c,d ->create(a,b,c,d)}




/** Create a new [MutableVec2] vector initialized with summed values of respective components of [this] and [k]*[b]. *//*

fun <T:Number,V: Vector2<T, K>,K: Vector2<T, K>> V.plusScaled(k: T, v: K) = plusScaled(k, v){a,b->create(a,b)}

*/
/** Create a new [MutableVec3] vector initialized with summed values of respective components of [this] and [k]*[b]. *//*

fun <T:Number,V: Vector3<T, K>,K: Vector3<T, K>> V.plusScaled(k: T, v: K) = plusScaled(k, v){a,b,c ->create(a,b,c)}

*/
/** Create a new [MutableVec4] vector initialized with summed values of respective components of [this] and [k]*[b]. *//*

fun <T:Number,V: Vector4<T, K>,K: Vector4<T, K>> V.plusScaled(k: T, v: K) = plusScaled(k, v){a,b,c,d ->create(a,b,c,d)}
*/
